package com.sgxy.aclservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sgxy.aclservice.entity.AclEmp;
import com.sgxy.aclservice.entity.AclEmpRole;
import com.sgxy.aclservice.entity.AclRole;
import com.sgxy.aclservice.mapper.AclRoleMapper;
import com.sgxy.aclservice.service.AclEmpRoleService;
import com.sgxy.aclservice.service.AclEmpService;
import com.sgxy.aclservice.service.AclRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sgxy.servicebase.exceptionhandler.ERPException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 角色 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-04-27
 */
@Service
public class AclRoleServiceImpl extends ServiceImpl<AclRoleMapper, AclRole> implements AclRoleService {

    // 删除角色
    @Autowired
    private AclEmpService aclEmpService;
    @Override
    public boolean deleteRoleById(String id) {
        QueryWrapper<AclEmp> wrapper = new QueryWrapper<>();
        wrapper.eq("role_id",id);
        int count = aclEmpService.count(wrapper);
        if(count>0){
            throw new ERPException(20001,"该角色正被使用，无法删除");
        }
        baseMapper.deleteById(id);
        return true;
    }
}
